package com.crl.module.goods.model.vo
{
	import com.crl.module.goods.events.InfoEvent;
	
	import flash.events.EventDispatcher;
	
	public class InfoBase extends EventDispatcher
	{
		protected var propetys:Object;
		public function InfoBase(data:Object=null)
		{
			this.propetys=new Object();
			setData(data);
		}
		
		/**
		 * 把data里面的所有属性拷贝到Info中
		 */
		public function setData(data:Object, fireEvent:Boolean=true):void{
			for(var i:String in data){
				if(this.hasOwnProperty(i)){
					this[i]=data[i];
				}else{
					propetys[i] = data[i];
				}
			}
			if(fireEvent){
				dispatchEvent(new InfoEvent(InfoEvent.INFO_CHANGED));
			}
		}
		
		public function setValue(key:String, value:*, fireEvent:Boolean=true):void{
			var d:Object = {};
			d[key] = value;
			setData(d, fireEvent);
		}
		
		public function getString(key:String, defaultValue:String=""):String{
			if(propetys[key] == undefined){
				return defaultValue;
			}
			return propetys[key].toString();
		}
		
		public function getInt(key:String, defaultValue:int=-1):int{
			if(propetys[key] != null && (propetys[key] is int || propetys[key] is Number)){
				return propetys[key];
			}
			return defaultValue;
		}
		
		public function getNumber(key:String, defaultValue:Number=-1):Number{
			if(propetys[key] != null && (propetys[key] is int || propetys[key] is Number)){
				return propetys[key];
			}
			return defaultValue;
		}
		
		public function getBoolean(key:String, defaultValue:Boolean=false):Boolean{
			if(propetys[key] == undefined){
				return defaultValue;
			}
			return propetys[key] === true;
		}

		public function getValue(key:String, defaultValue:*=undefined):*{
			if(propetys[key] == undefined){
				return defaultValue;
			}
			return propetys[key];
		}
		
		public function containsKey(key:String):Boolean{
			return propetys[key] !== undefined;
		}
		
		public function getInfo():Object{
			return propetys;
		}
		
		
	}
}